﻿<div ng-controller="LockOrderListC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">锁价单管理</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <!--<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <button class="btn btn-sm btn-default" ng-click="add()">
                        <i class="fa fa-plus text"></i>
                        <span class="text">添加</span>
                    </button>
                </div>-->
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <span class="input-group-addon">按客户名查找</span>
                    <input type="text" class="form-control" id="findname" placeholder="按客户名查找" ng-model="findname">
                    <span class="input-group-addon">按状态查找</span>
                    <select class="form-control" ng-model="typename">
                        <option value="">请选择状态</option>
                        <option value="3">审批中</option>
                        <option value="4">已暂停</option>
                        <option value="6">取消</option>
                        <option value="7">审核通过</option>
                        <option value="9">已退款</option>
                    </select>
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                    </span>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                        <tr>
                            <th style="text-align: center;">客户名</th>
                            <th style="text-align: center;">客户经理</th>
                            <th style="text-align: center;">锁价单总额</th>
                            <th style="text-align: center;">标件</th>
                            <th style="text-align: center;">地址</th>
                            <th style="text-align: center;">备注</th>
                            <th style="text-align: center;">状态</th>
                            <th style="text-align: center;">创建时间</th>
                            <th style="text-align: center;">详情</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in lockOrders">
                            <td style="width:150px">{{item.Customer.ShortName}}</td>
                            <td style="width:200px">{{item.Creater.Name}}</td>
                            <td style="width:150px">{{item.Total}}</td>
                            <td style="width:80px">
                                <span ng-if="item.IsStandard">标件</span>
                                <span ng-if="!item.IsStandard">非标件</span>
                            </td>
                            <td style="width:100px">{{item.District.Name}}</td>
                            <td>{{item.Remarks}}</td>
                            <td style="width:150px">
                                <span ng-if="item.IsApproval">审批中</span>
                                <span ng-if="item.IsPause">已暂停</span>
                                <span ng-if="!item.IsPause&&!item.IsApproval">
                                    <span ng-if="item.ProcessState == 0">正常</span>
                                    <span ng-if="item.ProcessState == 1">议价</span>
                                    <span ng-if="item.ProcessState == 2">锁价</span>
                                    <span ng-if="item.ProcessState == 3">款项确认</span>
                                    <span ng-if="item.ProcessState == 4">完结</span>/
                                    <span ng-if="item.State == 0">待确认</span>
                                    <span ng-if="item.State == 6">取消</span>
                                    <span ng-if="item.State == 7">审核通过</span>
                                    <span ng-if="item.State == 9">已退款</span>
                                </span>
                            </td>
                            <td style="width:200px">{{item.CreateTime}}</td>
                            <td style="width:60px">
                                <button class="btn btn-sm btn-default" ng-click="detail($index)">
                                    <i class="fa fa-file-text-o text"></i>
                                    <span class="text">详情</span>
                                </button>
                            </td>

                        </tr>
                    </tbody>
                </table>
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app') //锁价单列表控制器
    .controller("LockOrderListC", function ($scope, $state, $http, toSave) {
        $scope.pageData = {};
        $scope.pageData.Page = 0;
        $scope.findname = "";
        $scope.typename = "";
        $scope.pageData.Rows = $scope.defPageRows;
        $scope.getData = function (p, r, keyword) {
            if (p) {
                p = p < 1 ? 1 : p;
            } else p = 1;
            if (r) {
            } else r = $scope.defPageRows;
            toSave.save_pages_lis(p, r);//保存当前页码和条数
            $http({
                url: "../api/LockOrder/List?page=" + p + "&rows=" + r + "&state=" + $scope.typename + "&keyword=" + $scope.findname,
                method: "GET"
            })
                    .then(function (res) {
                        $scope.lockOrders = res.data.Data;
                        $scope.pageid = res.data.Page;
                        $scope.pageData = res.data;
                    })
                    .then(function (error) {
                        if (error) {
                            alert("数据获取失败");
                        }
                    });
        };
        $scope.add = function (index) {
            $state.go('app.LockOrder_Add');
        };
        $scope.detail = function (index) {
            $state.go('app.LockOrder_Detail', {
                orderid: JSON.stringify($scope.lockOrders[index].Id)
            });
        };
        //加载数据
        // $scope.getData(1, $scope.pageData.Rows);

        $scope.find = function () {
            $scope.getData(1, $scope.pageData.Rows);
            toSave.save_inputs();//点击查询先保存input里面的值
        };
        if (toSave.get_inputs('findname')) {
            $scope.findname = toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
            $scope.getData(toSave.get_pages(), toSave.get_lis());
        } else {
            $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
        }
    });
</script>
<script src="js/services/toSave.js"></script>
